package main

/*
#ifndef _V3_REG_XXX1_H__
#define _V3_REG_XXX1_H__
//#cgo CFLAGS: -I/Applications/DevEco-Studio.app/Contents/sdk/default/openharmony/native/sysroot/usr/include
#include <stdlib.h>

typedef int (*event_callback_func)(const char* s);

static int bridge_event_callback(event_callback_func cb, const char* event )
{
	return cb(event);
}
#endif
*/
import "C"
import "fmt"
import "unsafe"

type EventCallbackFunc C.event_callback_func

//export Test
func Test(s *C.char) C.int {
	fmt.Println("Test", C.GoString(s))
	return 502
}

//export RegEvent
func RegEvent(s *C.char, funcPtr EventCallbackFunc) C.int {
	fmt.Println("do_event", C.GoString(s))

	data := `
{
 "userId": 8472,
 "username": "vYk9sZtL8wR1gDpA",
 "email": "user123@example.com",
 "isActive": true,
 "lastLogin": "2025-04-02T15:30:00Z",
 "preferences": {
  "theme": "dark",
  "language": "en"
 },
 "items": [
  { "itemId": 101, "itemName": "Laptop", "price": 999.99 },
  { "itemId": 102, "itemName": "Mouse", "price": 25.49 }
 ]
}
`
	cData := C.CString(data)
	defer C.free(unsafe.Pointer(cData))

	result := C.bridge_event_callback(funcPtr, cData)
	if result != 0 {
		return 1
	}
	return 0
}

func main() {}
